package com.maven.front.service.manageComments;

import com.maven.front.bean.EduComment;
import com.maven.front.bean.EduUser;
import com.maven.front.dto.EduCommentDto;
import com.maven.front.mapper.EduCommentMapper;
import com.maven.front.mapper.EduUserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class EduCommentService {

    @Resource
    private EduCommentMapper eduCommentMapper;
    @Resource
    private EduUserMapper eduUserMapper;


//查询
 public List<EduCommentDto> list(EduComment eduComments){
   List<EduComment>list=this.eduCommentMapper.select(eduComments);
   List<EduCommentDto>list2=new ArrayList<EduCommentDto>();
   list.stream().forEach(eduComment -> {
       list2.add(changeEduCommentDto(eduComment));
   });
   return list2;

 }


 private EduCommentDto changeEduCommentDto(EduComment eduComment){
     EduCommentDto dto=new EduCommentDto();
     BeanUtils.copyProperties(eduComment,dto);
     dto.setEmail(this.eduUserMapper.selectByPrimaryKey(eduComment.getUserId()).getEmail());

     return dto;
 }

//编辑
  public int update(EduComment eduComment){
     return  this.eduCommentMapper.updateByPrimaryKeySelective(eduComment);
  }
 //根据id获取
  public EduComment init(int id){
     return  this.eduCommentMapper.selectByPrimaryKey(id);
  }


//删除
  public int delete(int id){
     return this.eduCommentMapper.deleteByPrimaryKey(id);
  }

    //根据id获取
  public EduUser selectkey(int id){
     return  this.eduUserMapper.selectByPrimaryKey(id);
  }
 //查询全部
  public List<EduUser> select(EduUser eduUser){
     return  this.eduUserMapper.select(eduUser);
  }

}
